/*    */ package org.yaukie.auth.service.impl;
/*    */ 
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.security.core.userdetails.UserDetails;
/*    */ import org.springframework.security.core.userdetails.UserDetailsService;
/*    */ import org.springframework.security.core.userdetails.UsernameNotFoundException;
/*    */ import org.springframework.stereotype.Service;
/*    */ import org.yaukie.auth.constant.AuthCons;
/*    */ import org.yaukie.auth.entity.LoginUser;
/*    */ import org.yaukie.base.core.entity.XUser;
/*    */ import org.yaukie.base.core.entity.XUserExample;
/*    */ import org.yaukie.base.core.service.api.XUserService;
/*    */ import org.yaukie.base.exception.UserDefinedException;
/*    */ import org.yaukie.base.util.MessageTools;
/*    */ import org.yaukie.base.util.StringTools;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Service
/*    */ public class UserDetailServiceImpl
/*    */   implements UserDetailsService
/*    */ {
/* 27 */   private static final Logger log = LoggerFactory.getLogger(UserDetailServiceImpl.class);
/*    */ 
/*    */   
/*    */   @Autowired
/*    */   private XUserService xUserService;
/*    */ 
/*    */   
/*    */   public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
/* 35 */     XUserExample xUserExample = new XUserExample();
/* 36 */     xUserExample.createCriteria().andUserNameEqualTo(userName);
/* 37 */     XUser xUser = (XUser)this.xUserService.selectFirstExample(xUserExample);
/* 38 */     if (StringTools.isNull(xUser)) {
/*    */       
/* 40 */       log.info("当前用户：{} 不存在.", userName);
/* 41 */       throw new UserDefinedException(MessageTools.message("yaukie.user.not.exists", new Object[0]));
/*    */     } 
/* 43 */     if (AuthCons.UserStatus.DELETED.getCode().equals(xUser.getDelFlag())) {
/*    */       
/* 45 */       log.info("当前用户：{} 已被删除.", userName);
/* 46 */       throw new UserDefinedException("对不起，您的账号：" + userName + " 已被删除");
/*    */     } 
/* 48 */     if (AuthCons.UserStatus.DISABLE.getCode().equals(xUser.getStatus())) {
/*    */       
/* 50 */       log.info("当前用户：{} 已被停用.", userName);
/* 51 */       throw new UserDefinedException("对不起，您的账号：" + userName + " 已停用");
/*    */     } 
/* 53 */     return createLoginUser(xUser);
/*    */   }
/*    */ 
/*    */   
/*    */   private UserDetails createLoginUser(XUser xUser) {
/* 58 */     LoginUser loginUser = new LoginUser();
/* 59 */     loginUser.setXUser(xUser);
/* 60 */     return loginUser;
/*    */   }
/*    */ }


/* Location:              /Users/rex/Desktop/x-common-auth-1.0.0-SNAPSHOT.jar!/org/yaukie/auth/service/impl/UserDetailServiceImpl.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */